import math
import numpy
# Known sample rate of the data set.
fs = 16e3;

segmentDuration = 1;
frameDuration = 0.025;
hopDuration = 0.010;

FFTLength = 512;
numBands = 50;

segmentSamples = round(segmentDuration * fs);
frameSamples = round(frameDuration * fs);
hopSamples = round(hopDuration * fs);
overlapSamples = frameSamples - hopSamples;

afe = None

# transform1 = transform(adsTrain,@(x)[zeros(floor((segmentSamples-size(x,1))/2),1);x;zeros(ceil((segmentSamples-size(x,1))/2),1)]);
def transform1(x):
    y = numpy.zeros([segmentSamples])
    w = x.shape[0]

    start = math.floor((segmentSamples - w) / 2)
    end = math.floor((segmentSamples - w) / 2) + w
    y[start:end] = x
    return y



# transform2 = transform(transform1,@(x)extract(afe,x));
def transform2(x):
    bark_spectrum = afe.extract(x)
    return bark_spectrum


# transform3 = transform(transform2,@(x){log10(x+1e-6)});
def transform3(x):
    y = numpy.log10(x+1e-6)
    return y

def gen_spectrogram(data):
    spectrogram = transform3(transform2(transform1(data)))
    return spectrogram